package cn.edu.stu.syllabus.library.list;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import javax.inject.Inject;

import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.base.BaseActivity;
import cn.edu.stu.syllabus.repository.library.LibrarySearchInfo;
import cn.edu.stu.syllabus.utils.ActivityUtils;
import cn.edu.stu.syllabus.utils.ExtraNameJoiner;
import cn.edu.stu.syllabus.utils.GuideHelper;

public class QueryBooksListActivity extends BaseActivity {

    @Inject
    QueryBooksListPresenter mQueryBooksListPresenter;

    private static final String EXTRA_LIBRARY_SEARCH_INFO = ExtraNameJoiner.join(
            QueryBooksListActivity.class, LibrarySearchInfo.class.getSimpleName());

    @Override
    protected int getContentViewId() {
        return R.layout.activity_query_books_list;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setTitle("搜索结果");


        QueryBooksListFragment queryBooksListFragment = (QueryBooksListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.contentFrame);
        if (queryBooksListFragment == null) {
            queryBooksListFragment = QueryBooksListFragment.newInstance();
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
                    queryBooksListFragment, R.id.contentFrame);
        }

        setOnToolbarDoubleClickListener(queryBooksListFragment);


        LibrarySearchInfo searchInfo = getIntent().getParcelableExtra(EXTRA_LIBRARY_SEARCH_INFO);

        DaggerQueryBooksListComponent.builder()
                .queryBooksListPresenterModule(
                        new QueryBooksListPresenterModule(queryBooksListFragment, searchInfo))
                .build().inject(this);

        GuideHelper.startActSeqNow(this,
                GuideHelper.getActMainTapTarget(R.drawable.ic_oa, this,
                        "这是搜索结果主界面",
                        "顶部下拉可以进行刷新\n底部上拉可以加载更多\n双击Title可以立刻回到顶部")
                        .id(1)
        );

    }

    public static Intent newIntent(Context context, LibrarySearchInfo searchInfo) {
        Intent intent = new Intent(context, QueryBooksListActivity.class);
        intent.putExtra(EXTRA_LIBRARY_SEARCH_INFO, searchInfo);
        return intent;
    }


}
